<template>
	<!-- 员工详情 -->
  <div class="stu">
	 <el-dialog v-loading="loading"  :title="'新增贫困户信息'" :visible.sync="dialogVisible" width="35%" :before-close="handleClose"  :close-on-click-modal='false'>
	   <!-- <p class="pbox" style="text-align: center;width:100%;font-size:30px;height:40px;">员工信息详情</p> -->

	    <div style="width:100%;padding-bottom:20px;">
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>选择地区</p>
					<el-select style='width:37%;' @change='activess.group_name="";activess.pover_cadre_id="";activess.poor_house_id="";git_gan();pkhbox=[]' v-model="activess.village_name" clearable filterable placeholder="选择行政村">
					  <el-option v-for='i in $store.state.cunid' :label="i.label" :value="i.label"></el-option>
					</el-select>
					<el-select style='width:37%;' @change="activess.poor_house_id='';git_pin();" v-model="activess.group_name" clearable filterable placeholder="选择村组">
					  <el-option v-for='i in activeput(gitcode(activess.village_name,$store.state.cunid),$store.state.cunzuid)' :label="i.label" :value="i.label"></el-option>
					</el-select>
			</div>
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>扶贫干部</p>
					<el-select style="width:75%;border:none;" @change="obtainValue" class="pboxc1" v-model="activess.pover_cadre_id" clearable filterable placeholder="请选择">
					  <el-option v-for='item in ganbox' :key='item.id' :label="item.name" :value="item.id"></el-option>
					</el-select>
			</div>
			<div style="margin-top:10px;" class="tabbox">
					<p style="width:15%;"><a style="color:red;">* </a>贫困户</p>
					<el-select style="width:75%;border:none;" class="pboxc1" v-model="activess.poor_house_id" clearable filterable placeholder="请选择">
					  <el-option v-for='item in pkhbox' :label="item.pop_name" :value="item.id"></el-option>
					</el-select>
			</div>
    
		</div>	
		<div style="width:100%;height:40px;margin-top:20px;">
	      <div style="width:170px;margin: 0 auto;">
	        <el-button type="danger" @click="handleClose">取 消</el-button>
	        <el-button type="primary" style='float:right;' @click="git_acts">确 定</el-button>
	      </div>
		</div>
	 </el-dialog>
	
  </div>
</template>

<script>
import $ from 'jquery'
export default {
  name: 'stu',
  components: {},//声明子组件
  computed:{
	  activeput(){//联动判断，code 为上一级的code  act为当前未赛选的数据字典
	  	return function(code,act){
	  		let a = [];
	  		for(let i=0;i<act.length;i++){
	  			if(act[i].own_code==code){
	  				a.push(act[i]);
	  			}
	  		}
	  		return a;
	  	}
	  },
	  gitcode(){//通过id获取code
	  	return function(id,act){
	  		for(let i=0;i<act.length;i++){
	  			if(id==act[i].label){
	  				return act[i].code;
	  			    break
	  			}
	  		}
	  	}
	  },
  },
  data(){
	  return {
		loading:false,
		btn_shou:false,
		dialogVisible: false,
		activess:{
				  village_name:'',//村名
				  group_name:'',//组名
				  pover_cadre_id:'',//干部ID
                  poor_house_id:'',//贫困户表的ID
				  
		},
		
		renbox:[],
		num:0,     
		ganbox:[],//干部数据列表
		pkhbox:[],//平困户数据表
	  }
  },
  methods:{
	  obtainValue(value){
		 console.log(this.activess.cadre_id);  
	  },
	  
	  
	  git_act(i,num){//获取数据的同打开狂口
	      // this.git_gan();
	      if(num==1){
			  this.activess = i;
			  this.git_gan();
			  this.git_pin();
			//   this.activess.p_number = this.activess.poor_pop[0].p_number;
			  console.log(this.activess);
		  }
		  this.num = num;
	      // console.log(this.activess,num);
	      this.dialogVisible=true;
	  },
	  git_acts(){//提交数据
	        console.log(this.activess)
	        if(this.isNull(this.activess.village_name)){this.$message.error('请选择 行政村');return false}
	        if(this.isNull(this.activess.group_name)){this.$message.error('请选择 村组');return false}
			if(this.isNull(this.activess.pover_cadre_id)){this.$message.error('请选择 干部');return false};
			if(this.isNull(this.activess.poor_house_id)){this.$message.error('请选择 贫困户');return false}
	  		 // let url = this.num==1?'/dj/user_pc/poor_modify':'/dj/user_pc/cadre_poor_insert';
	  		 $.ajax({url:'/dj/user_pc/cadre_poor_insert',type:'post',data:this.activess,dataType:'json',success:(res)=> {
	  		 	if(Object.prototype.toString.call(res) != '[object Object]'){res = JSON.parse(res)}
	  		 	 console.log(res,'提交');
	  		 	 if(res.code==200){
	  				this.$parent.git_act();
	  		 		this.$message({message: '操作成功',type: 'success'});
	  		 		this.dialogVisible=false;
	  				this.qin();
	  		 	  }else{
	  		 		 this.$message.error(res.msg);
	  		 	  }
	  		 	}
	  		 })
	  },
	  qin(){//清除
	  	this.activess={
				  village_name:'',//村名
				  group_name:'',//组名
				  pover_cadre_id:'',//干部ID
                  poor_house_id:'',//贫困户表的ID
				  id:'',//贫困人口ID（主键）
		}
		this.ganbox=[];//干部数据列表
		this.pkhbox=[];//平困户数据表
	  },
	  
	  handleClose(done){//监测用户点击x
	     this.$confirm('确定取消关闭吗？','提示',{confirmButtonText:'确定',cancelButtonText:'取消',type: 'warning'
	     }).then(() => {
	  	   this.dialogVisible = false;
	  	   this.qin();
		   this.$parent.git_act();
	  	}).catch(() => {});
	  },
                                          
      git_gan(){//获取干部信息
           $.ajax({url:'/dj/user_pc/get_cadre_house',type:'post',data:{village_name:this.activess.village_name},dataType:'json',success:(res)=> {
	  		 	if(Object.prototype.toString.call(res) != '[object Object]'){res = JSON.parse(res)}
	  		 	 console.log(res,'干部信息');
	  		 	 if(res.code==200){
					this.ganbox = res.data;
	  		 		// this.$message({message: '操作成功',type: 'success'});
	  		 	  }else{
	  		 		 this.$message.error(res.msg);
	  		 	  }
	  		 	}
           })
	  },
       git_pin(){//获取平困户
           $.ajax({url:'/dj/user_pc/get_poor_house_list',type:'post',data:{
					village_name:this.activess.village_name,
					group_name:this.activess.group_name,
					page:1,
					size:100000	
			   },dataType:'json',success:(res)=> {
	  		 	if(Object.prototype.toString.call(res) != '[object Object]'){res = JSON.parse(res)}
	  		 	 console.log(res,'平困户');
	  		 	 if(res.code==200){
					this.pkhbox = res.data;
	  		 		// this.$message({message: '操作成功',type: 'success'});
	  		 	  }else{
	  		 		 this.$message.error(res.msg);
	  		 	  }
	  		 	}
           })
	  },


  },
  mounted(){
	  
	  // this.git_ren()
  }
}
</script>
<style scoped="scoped">
	
	.pboxc1{
		float:left;
		width:70%;
		height:40px;
		border:1px solid rgba(242,242,242,1);
		font-size:14px;color:#666666;
		/* padding-left:18px; */
		text-align:left;
		/* overflow: hidden; */
		/* text-overflow:ellipsis; */
		/* white-space: nowrap; */
	}
	.tabbox{
		width:100%;
		height:40px;
		line-height: 30px;
		margin-top:23px;
	}
	.tabbox p{
		font-size:14px;
		color:#000000;
		width:19.5%;
		text-align:right;
		margin-right:28px;
		float:left;
		overflow: hidden;
		text-overflow:ellipsis;
		white-space: nowrap;
		font-family:Source Han Sans CN;
	}
	.pbox{
		width:10%;
		text-align:right;
		height:26px;
		margin-bottom:20px;
		font-size:18px;
		color:#000101;
		overflow: hidden;
		text-overflow:ellipsis;
		white-space: nowrap;
		font-family:Source Han Sans CN;
		font-weight:600;
	}
</style>
